import Taro from '@tarojs/taro-rn';
import * as tslib_1 from "tslib";
import React from 'react';
import { Component } from "@tarojs/taro-rn";
import { View, Image, Text } from "@tarojs/components-rn";
import { toJS } from 'mobx';
import { inject, observer } from "@tarojs/mobx-rn";
import { getRuntime, pageSize, subtime } from "../../utils/common";
import apply_logStyleSheet from "./apply_log_styles";
import none_people from "../../assets/img/none_people.png";
var _styleSheet = apply_logStyleSheet;
let ApplyLog = class ApplyLog extends Component {
  constructor(props) {
    super(props);
    this.state = {
      pageIndex: 1,
      pageSize,
      items: [],
      totalCount: 0
    };
  }
  componentWillMount() {
    Taro.setNavigationBarTitle({ title: '我的申请' });
    this.getMyApplication();
  }
  handelRouter(url = '/pages/index/index') {
    getRuntime().navigateTo(url);
  }
  getMyApplication() {
    let { userStore } = this.props.stores;
    let { pageIndex, pageSize } = this.state;
    userStore.getMyApplication({
      pageIndex,
      pageSize,
      callback: res => {
        if (pageIndex === 1) {
          this.setState({ totalCount: toJS(res.totalCount), items: toJS(res.items) });
        } else {
          const { items } = this.state;
          items.push(...(res.items || []));
          this.setState({ totalCount: res.totalCount, items });
        }
      }
    });
  }
  onReachBottom() {
    let { totalCount, pageSize, pageIndex } = this.state;
    const { loading } = this.props.stores.homeStore;
    if (totalCount > pageIndex * pageSize && !loading) {
      this.setState({
        pageIndex: pageIndex + 1
      }, () => {
        this.getMyApplication();
      });
    }
  }
  render() {
    let { items } = this.state;
    return <View style={_styleSheet["my-my_integral"]}>
        {items.length > 0 && items.map(item => {
        return <View style={_styleSheet["list-19-item"]}>
              <View style={_styleSheet["l"]}>
                <View style={_styleSheet["list-title"]}>{item.typeName}</View>
                <View style={_styleSheet["list-info"]}>{subtime(item.creationTime)}</View>
              </View>
              {item.status === 1 && <View style={[_styleSheet["r"], _styleSheet["apply-res"]]}>
                 <Text style={_styleSheet["res"]}>处理中...</Text>
              </View>}
              {item.status === 2 && <View style={[_styleSheet["r"], _styleSheet["apply-res"]]}>
                 <Text style={_styleSheet["res"]}>办理成功</Text>
              </View>}
              {item.status === 3 && <View style={[_styleSheet["r"], _styleSheet["apply-res"]]}>
                 <Text style={[_styleSheet["res"], _styleSheet["color"]]}>办理失败</Text>
                 <Text style={[_styleSheet["desc"], _styleSheet["color"]]}>原因：{item.reason}</Text>
              </View>}
            </View>;
      })}

        {items.length <= 0 && <View style={_styleSheet["none-info"]}>
           <Image src={none_people} style={_styleSheet["none-icon"]} />
           <Text style={[_styleSheet["none-title"], _styleSheet["list-desc"]]}>您还没有任何申信息~</Text>
        </View>}
      </View>;
  }
};
ApplyLog = tslib_1.__decorate([inject("stores"), observer], ApplyLog);
export default ApplyLog;